/**
 *
 */
package com.zhuoyue.elmt.service;

import java.util.List;

import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.elmt.dao.FailureReportDao;
import com.zhuoyue.elmt.entity.FailureReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.service.CrudService;
import com.zhuoyue.elmt.entity.FailureSurveyContent;
import com.zhuoyue.elmt.dao.FailureSurveyContentDao;

/**
 * 电梯故障调查内容Service
 *
 * @author chenhao
 * @version 2016-09-07
 */
@Service
@Transactional(readOnly = true)
public class FailureSurveyContentService extends CrudService<FailureSurveyContentDao, FailureSurveyContent> {

    @Autowired
    private FailureReportDao failureReportDao;

    public FailureSurveyContent get(String id) {
        return super.get(id);
    }

    public List<FailureSurveyContent> findList(FailureSurveyContent failureSurveyContent) {
        return super.findList(failureSurveyContent);
    }

    public Page<FailureSurveyContent> findPage(Page<FailureSurveyContent> page, FailureSurveyContent failureSurveyContent) {
        return super.findPage(page, failureSurveyContent);
    }

    @Transactional(readOnly = false)
    public void save(FailureSurveyContent failureSurveyContent) {
        super.save(failureSurveyContent);
    }

    @Transactional(readOnly = false)
    public void delete(FailureSurveyContent failureSurveyContent) {
        super.delete(failureSurveyContent);
    }

    @Transactional(readOnly = false)
    public void saveOrUpdate(FailureReport failureReport, List<FailureSurveyContent> failureSurveyContents) {
        // 更新故障报检基本情况
        failureReport.preUpdate();
        failureReportDao.update(failureReport);

        for (int i = 0; i < failureSurveyContents.size(); i++) {
            FailureSurveyContent failureSurveyContent = failureSurveyContents.get(i);
            if (StringUtils.isEmpty(failureSurveyContent.getContentId())) {
                insert(failureSurveyContent);
            } else {
                update(failureSurveyContent);
            }
        }
    }

    @Transactional(readOnly = false)
    public void saveOrUpdate(List<FailureSurveyContent> failureSurveyContents) {
        for (int i = 0; i < failureSurveyContents.size(); i++) {
            FailureSurveyContent failureSurveyContent = failureSurveyContents.get(i);
            if (StringUtils.isEmpty(failureSurveyContent.getContentId())) {
                insert(failureSurveyContent);
            } else {
                update(failureSurveyContent);
            }
        }
    }
}